package leetcode.code0503;

import java.util.Arrays;
import java.util.Stack;

import leetcode.IDebug;
import leetcode.helper.H;

public class Solution implements IDebug {

	public int[] nextGreaterElements(int[] nums) {
		Stack<Integer> stack = new Stack<>();
		int len = nums.length;
		int[] ans = new int[len];
		Arrays.fill(ans, -1);
		for (int i = 0; i < nums.length << 1; i++) {
			int num = nums[i % len];
			while (!stack.isEmpty() && nums[stack.peek()] < num) {
				int cur = stack.pop();
				ans[cur] = num;
			}
			stack.add(i % len);
		}
		return ans;
	}

	@Override
	public void debug4() {
//		H.compare(H.str2array3("[2,3,4,-1,4]"), this.nextGreaterElements(H.str2array3("[1,2,3,4,3]")));
		H.compare(H.str2array3("[-1,5,5,5,5]"), this.nextGreaterElements(H.str2array3("[5,4,3,2,1]")));

	}

	@Override
	public void debug3() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug2() {
		// TODO Auto-generated method stub

	}

	@Override
	public void debug1() {

	}

	public static void main(String[] args) {
		Solution so = new Solution();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();

	}

}
